enum HTTPMethod { GET, POST, DELETE }

abstract class BaseRequest {
  var pathParams;

  var useHttps = true;

  HTTPMethod method();

  String baseURL() {
    return 'api.devio.org';
  }

  String path();

  String url() {
    Uri uri;
    var pathStr = path();
    if (pathParams != null) {
      if (baseURL().endsWith('/')) {
        pathStr = "${path()}${pathParams}";
      } else {
        pathStr = "${path()}/${pathParams}";
      }
    }

    if (useHttps) {
      uri = Uri.https(baseURL(), pathStr, params);
    } else {
      uri = Uri.http(baseURL(), pathStr, params);
    }

    return uri.toString();
  }

  bool needLogin() {
    return true;
  }

  Map<String, String> params = Map();

  BaseRequest add(String k, Object v) {
    params[k] = v.toString();
    return this;
  }

  Map<String, dynamic> headers = {
    "course-flag": 'fa', //访问令牌，在课程公告获取
    "auth-token": "MjAyMC0wNi0yMyAwMzoyNTowMQ==fa",
  };

  BaseRequest addHeader(String k, String v) {
    headers[k] = v.toString();
    return this;
  }
}
